package org.elong.qadev.reflect;

import java.lang.reflect.Field;

/**
 * 
* @ClassName: ReflectGetElement
* @Description: TODO(通过类路径活类本身获取类属性数量和名称)
* @author kangchen
* @date 2015年10月15日
*
 */
public class ReflectGetElement {

	public ReflectGetElement() {

	}

	public static String[] getElements(String classPath) {
		String[] elements;
		Class<?> clazz;
		Field[] field = null;
		try {
			clazz = Class.forName(classPath);
			//Object obj = clazz.newInstance();
			field = clazz.getDeclaredFields();

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
		elements = new String[field.length];
		for (int i = 0; i < elements.length; i++) {
			elements[i] = field[i].getName();
		}
		return elements;
	}
	
	public static String[] getElementsByClass(Class<?> input) throws ClassNotFoundException {
		String[] elements;
		Field[] field = null;
		try {
			field = input.getDeclaredFields();
		} catch (SecurityException e) {
			e.printStackTrace();
		}
		elements = new String[field.length];
		for (int i = 0; i < elements.length; i++) {
			elements[i] = field[i].getName();
		}
		return elements;
	}

}
